<!DOCTYPE html>












  


<html class="theme-next muse use-motion" lang="zh-CN">
<head><meta name="generator" content="Hexo 3.9.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">






















<link rel="stylesheet" href="/lib/font-awesome/css/font-awesome.min.css?v=4.7.0">

<link rel="stylesheet" href="/css/main.css?v=7.1.2">


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=7.1.2">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=7.1.2">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=7.1.2">


  <link rel="mask-icon" href="/images/logo.svg?v=7.1.2" color="#222">







<script id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Muse',
    version: '7.1.2',
    sidebar: {"position":"left","display":"post","offset":12,"onmobile":false,"dimmer":false},
    back2top: true,
    back2top_sidebar: false,
    fancybox: false,
    fastclick: false,
    lazyload: false,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>


  




  <meta name="description" content="最近做个人微信机器人挺热门的， 同时很多人也用来对自己的微信好友做分析和统计， 比如：简单的就是利用微信好友的头像做成一张大图， 让朋友圈的好友都看到彼此， 觉得蛮有意思的! 网上已经有 Python 或 Nodejs 的实现了， 我就想用 PHP 来实现一下。">
<meta name="keywords" content="PHP,微信">
<meta property="og:type" content="article">
<meta property="og:title" content="手把手教你用 PHP 拼接微信好友头像">
<meta property="og:url" content="https://qimajiang.com/2017/06/13/手把手教你用-PHP-拼接微信好友头像/index.html">
<meta property="og:site_name" content="启码匠 - 磨刀霍霍向编程">
<meta property="og:description" content="最近做个人微信机器人挺热门的， 同时很多人也用来对自己的微信好友做分析和统计， 比如：简单的就是利用微信好友的头像做成一张大图， 让朋友圈的好友都看到彼此， 觉得蛮有意思的! 网上已经有 Python 或 Nodejs 的实现了， 我就想用 PHP 来实现一下。">
<meta property="og:locale" content="zh-CN">
<meta property="og:image" content="https://ws1.sinaimg.cn/large/006tKfTcgy1fgfalih389j30b40b40t8.jpg">
<meta property="og:image" content="https://ws1.sinaimg.cn/large/006tKfTcgy1fgfalhd9z8j30rs0m8acd.jpg">
<meta property="og:updated_time" content="2019-06-24T06:11:04.000Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="手把手教你用 PHP 拼接微信好友头像">
<meta name="twitter:description" content="最近做个人微信机器人挺热门的， 同时很多人也用来对自己的微信好友做分析和统计， 比如：简单的就是利用微信好友的头像做成一张大图， 让朋友圈的好友都看到彼此， 觉得蛮有意思的! 网上已经有 Python 或 Nodejs 的实现了， 我就想用 PHP 来实现一下。">
<meta name="twitter:image" content="https://ws1.sinaimg.cn/large/006tKfTcgy1fgfalih389j30b40b40t8.jpg">





  
  
  <link rel="canonical" href="https://qimajiang.com/2017/06/13/手把手教你用-PHP-拼接微信好友头像/">



<script id="page.configurations">
  CONFIG.page = {
    sidebar: "",
  };
</script>

  <title>手把手教你用 PHP 拼接微信好友头像 | 启码匠 - 磨刀霍霍向编程</title>
  












  <noscript>
  <style>
  .use-motion .motion-element,
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-title { opacity: initial; }

  .use-motion .logo,
  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope="" itemtype="http://schema.org/WebPage" lang="zh-CN">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope="" itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta">
    

    <div class="custom-logo-site-title">
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">启码匠 - 磨刀霍霍向编程</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
    
      
        <h1 class="site-subtitle" itemprop="description">磨刀霍霍向编程</h1>
      
    
    
  </div>

  <div class="site-nav-toggle">
    <button aria-label="切换导航栏">
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>



<nav class="site-nav">
  
    <ul id="menu" class="menu">
      
        
        
        
          
          <li class="menu-item menu-item-home">

    
    
    
      
    

    

    <a href="/" rel="section"><i class="menu-item-icon fa fa-fw fa-home"></i> <br>首页</a>

  </li>
        
        
        
          
          <li class="menu-item menu-item-archives">

    
    
    
      
    

    

    <a href="/archives/" rel="section"><i class="menu-item-icon fa fa-fw fa-archive"></i> <br>归档</a>

  </li>

      
      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br>搜索</a>
        </li>
      
    </ul>
  

  
    

  

  
    <div class="site-search">
      
  <div class="popup search-popup local-search-popup">
  <div class="local-search-header clearfix">
    <span class="search-icon">
      <i class="fa fa-search"></i>
    </span>
    <span class="popup-btn-close">
      <i class="fa fa-times-circle"></i>
    </span>
    <div class="local-search-input-wrapper">
      <input autocomplete="off" placeholder="搜索..." spellcheck="false" type="text" id="local-search-input">
    </div>
  </div>
  <div id="local-search-result"></div>
</div>



    </div>
  
</nav>



  



</div>
    </header>

    


    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  

  <article class="post post-type-normal" itemscope="" itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://qimajiang.com/2017/06/13/手把手教你用-PHP-拼接微信好友头像/">

    <span hidden itemprop="author" itemscope="" itemtype="http://schema.org/Person">
      <meta itemprop="name" content="启码匠">
      <meta itemprop="description" content="学习如磨刀， 需要不断温故。">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope="" itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="启码匠 - 磨刀霍霍向编程">
    </span>

    
      <header class="post-header">

        
        
          <h2 class="post-title" itemprop="name headline">手把手教你用 PHP 拼接微信好友头像

              
            
          </h2>
        

        <div class="post-meta">
          <span class="post-time">

            
            
            

            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              

              
                
              

              <time title="创建时间：2017-06-13 20:18:09" itemprop="dateCreated datePublished" datetime="2017-06-13T20:18:09+08:00">2017-06-13</time>
            

            
              

              
                
                <span class="post-meta-divider">|</span>
                

                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                
                  <span class="post-meta-item-text">更新于</span>
                
                <time title="修改时间：2019-06-24 14:11:04" itemprop="dateModified" datetime="2019-06-24T14:11:04+08:00">2019-06-24</time>
              
            
          </span>

          

          
            
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <ul>
<li>最近做个人微信机器人挺热门的， 同时很多人也用来对自己的微信好友做分析和统计， 比如：简单的就是利用微信好友的头像做成一张大图， 让朋友圈的好友都看到彼此， 觉得蛮有意思的! 网上已经有 Python 或 Nodejs 的实现了， 我就想用 PHP 来实现一下。<a id="more"></a>

</li>
</ul>
<h3 id="1、如何选一个微信爬虫。"><a href="#1、如何选一个微信爬虫。" class="headerlink" title="1、如何选一个微信爬虫。"></a>1、如何选一个微信爬虫。</h3><h4 id="所谓的微信爬虫就是利用微信的-web-api-做一些自动化的事情，这里强烈推荐由-PHP7实现的vbot-所有的东西都可以在-vbot-的文档里找到，-在微信-web-api-的范围内你都可以为所欲为了。注意：-本文所有的微信数据都基于-vbot-获取的。"><a href="#所谓的微信爬虫就是利用微信的-web-api-做一些自动化的事情，这里强烈推荐由-PHP7实现的vbot-所有的东西都可以在-vbot-的文档里找到，-在微信-web-api-的范围内你都可以为所欲为了。注意：-本文所有的微信数据都基于-vbot-获取的。" class="headerlink" title="所谓的微信爬虫就是利用微信的 web api 做一些自动化的事情，这里强烈推荐由 PHP7实现的vbot, 所有的东西都可以在 vbot 的文档里找到， 在微信 web api 的范围内你都可以为所欲为了。注意： 本文所有的微信数据都基于 vbot 获取的。"></a>所谓的微信爬虫就是利用微信的 web api 做一些自动化的事情，这里强烈推荐由 PHP7实现的<a href="https://github.com/HanSon/vbot" target="_blank" rel="noopener">vbot</a>, 所有的东西都可以在 vbot 的文档里找到， 在微信 web api 的范围内你都可以为所欲为了。注意： 本文所有的微信数据都基于 vbot 获取的。</h4><h3 id="2、如何爬取微信好友的头像。"><a href="#2、如何爬取微信好友的头像。" class="headerlink" title="2、如何爬取微信好友的头像。"></a>2、如何爬取微信好友的头像。</h3><h4 id="首先要获取的是你的微信好友列表，-在-vbot-的基础上我们可以这样做："><a href="#首先要获取的是你的微信好友列表，-在-vbot-的基础上我们可以这样做：" class="headerlink" title="首先要获取的是你的微信好友列表， 在 vbot 的基础上我们可以这样做："></a>首先要获取的是你的微信好友列表， 在 vbot 的基础上我们可以这样做：</h4><figure class="highlight php"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">File::saveTo(<span class="keyword">__DIR__</span>.<span class="string">'/contacts.json'</span>, $contacts[<span class="string">'friends'</span>]);</span><br></pre></td></tr></table></figure>

<h4 id="把微信好友列表写入到一个文件中。"><a href="#把微信好友列表写入到一个文件中。" class="headerlink" title="把微信好友列表写入到一个文件中。"></a>把微信好友列表写入到一个文件中。</h4><h4 id="然后对这个文件进行处理，-提取微信好友的头像链接和下载。"><a href="#然后对这个文件进行处理，-提取微信好友的头像链接和下载。" class="headerlink" title="然后对这个文件进行处理， 提取微信好友的头像链接和下载。"></a>然后对这个文件进行处理， 提取微信好友的头像链接和下载。</h4><figure class="highlight php"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">$contactAmount = $friends-&gt;count();</span><br><span class="line">   <span class="keyword">for</span>($i=<span class="number">0</span>; $i&lt; $contactAmount; $i++)&#123;</span><br><span class="line">     $data =  $friends-&gt;getAvatar(<span class="keyword">self</span>::$usernameArr[$i]);</span><br><span class="line">    file_put_contents(<span class="keyword">__DIR__</span>.<span class="string">'/avatars/'</span>.$i.<span class="string">'.jpeg'</span>,$data);</span><br><span class="line"></span><br><span class="line">   &#125;</span><br></pre></td></tr></table></figure>

<h4 id="就这样，-我们就已经能把所有的微信好友头像下载到指定的地方了。注意：建议图片的命名规则用数字递增的方式，-方便后面的图片拼接循环。"><a href="#就这样，-我们就已经能把所有的微信好友头像下载到指定的地方了。注意：建议图片的命名规则用数字递增的方式，-方便后面的图片拼接循环。" class="headerlink" title="就这样， 我们就已经能把所有的微信好友头像下载到指定的地方了。注意：建议图片的命名规则用数字递增的方式， 方便后面的图片拼接循环。"></a>就这样， 我们就已经能把所有的微信好友头像下载到指定的地方了。注意：建议图片的命名规则用数字递增的方式， 方便后面的图片拼接循环。</h4><h3 id="3、图片拼接"><a href="#3、图片拼接" class="headerlink" title="3、图片拼接"></a>3、图片拼接</h3><h4 id="本文的重点来了，-现在网上有很多图片拼接小工具，-但-PHP-实现的寥寥无几，-找了一轮后，-决定还是自己写。"><a href="#本文的重点来了，-现在网上有很多图片拼接小工具，-但-PHP-实现的寥寥无几，-找了一轮后，-决定还是自己写。" class="headerlink" title="本文的重点来了， 现在网上有很多图片拼接小工具， 但 PHP 实现的寥寥无几， 找了一轮后， 决定还是自己写。"></a>本文的重点来了， 现在网上有很多图片拼接小工具， 但 PHP 实现的寥寥无几， 找了一轮后， 决定还是自己写。</h4><p>（1）首先，要确定画布的长度和宽度。那怎么根据图片数量确定画布大小呢。我们门这样分析：由于微信头像的宽高相等， 那我们拼接到画布的托也是宽高相等，这里全部设置为200px， 那么， 只要确定行数和列数， 就知道画布的大小了。<strong>还有一点注意：当图片数量小于4张时， 我们只需要一行（或者一列）即可。</strong> 当图片数大于3时：</p>
<p>a、确定列数（每行多少张）：列数 = 总数（大于3）的平方根， 向上取整<br>b、确定行数（每列多少张）：总数（大于3）除以列数， 向上取整</p>
<ul>
<li>这里的行数和行数的计算方式是为了尽可能使画布的宽度和高度差值减小。你也可以根据自己的好修改计算方法， 但一定要跟后面的图片排列的行数和列数一致， 否则会出现图片越界的问题。</li>
</ul>
<p>知道了行数和列数， 那很容易得出画布的宽高  </p>
<p>c、画布宽度 = 图片宽度（200px）乘以 列数<br>d、画布高度 = 图片高度（200px）乘以 行数</p>
<p>代码如下：</p>
<figure class="highlight php"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment">   * 根据图片数据计算画布的大小</span></span><br><span class="line"><span class="comment">   * 默认每张图宽度高度 = 200</span></span><br><span class="line"><span class="comment">   * 画布大小计算方法：</span></span><br><span class="line"><span class="comment">   * 列数 = 总数（大于3）的平方根， 向上取整</span></span><br><span class="line"><span class="comment">   * 行数 = 总数（大于3）除以列数， 向上取整</span></span><br><span class="line"><span class="comment">   *  <span class="doctag">@param</span> $imageCount</span></span><br><span class="line"><span class="comment">   */</span></span><br><span class="line">  <span class="keyword">private</span> <span class="function"><span class="keyword">function</span>  <span class="title">prepareForCanvas</span><span class="params">($imageCount)</span></span>&#123;</span><br><span class="line">      $canvasWidth = <span class="number">0</span>;</span><br><span class="line">      $canvasHeight = <span class="number">0</span>;</span><br><span class="line">      <span class="keyword">if</span> ($imageCount &gt; <span class="number">0</span>) &#123;</span><br><span class="line"></span><br><span class="line">          <span class="comment">//宽度 = 列数*200</span></span><br><span class="line">          <span class="keyword">if</span> ($imageCount &lt; <span class="number">4</span>) &#123;</span><br><span class="line"></span><br><span class="line">                  $canvasWidth = <span class="keyword">$this</span>-&gt;width*$imageCount;</span><br><span class="line">                  <span class="keyword">$this</span>-&gt;eachLineCount = $imageCount;</span><br><span class="line">                  $canvasHeight = <span class="keyword">$this</span>-&gt;height;</span><br><span class="line">          &#125;<span class="keyword">else</span>&#123;</span><br><span class="line"></span><br><span class="line">              <span class="keyword">$this</span>-&gt;eachLineCount = ceil(sqrt($imageCount)); <span class="comment">//列数</span></span><br><span class="line">              <span class="keyword">$this</span>-&gt;eachColumCount = ceil($imageCount/<span class="keyword">$this</span>-&gt;eachLineCount);</span><br><span class="line">              $canvasWidth = <span class="keyword">$this</span>-&gt;width * <span class="keyword">$this</span>-&gt;eachLineCount;</span><br><span class="line">              $canvasHeight = <span class="keyword">$this</span>-&gt;height * <span class="keyword">$this</span>-&gt;eachColumCount;</span><br><span class="line">          &#125;</span><br><span class="line">      &#125;</span><br><span class="line">      <span class="keyword">echo</span> <span class="string">'图片总数：'</span>.$imageCount.PHP_EOL;</span><br><span class="line">      <span class="comment">//创建画布</span></span><br><span class="line">      <span class="keyword">$this</span>-&gt;createCanvas($canvasWidth, $canvasHeight);</span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">     <span class="comment">/**创建画布</span></span><br><span class="line"><span class="comment">   * <span class="doctag">@param</span> $width</span></span><br><span class="line"><span class="comment">   * <span class="doctag">@param</span> $height</span></span><br><span class="line"><span class="comment">   */</span></span><br><span class="line">  <span class="keyword">private</span> <span class="function"><span class="keyword">function</span> <span class="title">createCanvas</span><span class="params">($cwidth, $cheight)</span> </span>&#123;</span><br><span class="line">      $totalImage = count(<span class="keyword">$this</span>-&gt;srcImages);     </span><br><span class="line"></span><br><span class="line">      <span class="keyword">$this</span>-&gt;canvas = imagecreatetruecolor($cwidth, $cheight);</span><br><span class="line"></span><br><span class="line">      <span class="comment">// 使画布透明</span></span><br><span class="line">      $white = imagecolorallocate(<span class="keyword">$this</span>-&gt;canvas, <span class="number">255</span>, <span class="number">255</span>, <span class="number">255</span>);</span><br><span class="line">      imagefill(<span class="keyword">$this</span>-&gt;canvas, <span class="number">0</span>, <span class="number">0</span>, $white);</span><br><span class="line">      imagecolortransparent(<span class="keyword">$this</span>-&gt;canvas, $white);</span><br><span class="line">      <span class="keyword">echo</span> <span class="string">'画布大小:长度：'</span>.$cwidth.<span class="string">'，高度：'</span>. $cheight.PHP_EOL.</span><br><span class="line">          <span class="string">'每行数量（列数）：'</span>.<span class="keyword">$this</span>-&gt;eachLineCount.<span class="string">',每列数量（行数）：'</span>.<span class="keyword">$this</span>-&gt;eachColumCount.PHP_EOL;</span><br><span class="line">  &#125;</span><br></pre></td></tr></table></figure>

<h3 id="4、画布建好了，-接下来就是拼接图片了。"><a href="#4、画布建好了，-接下来就是拼接图片了。" class="headerlink" title="4、画布建好了， 接下来就是拼接图片了。"></a>4、画布建好了， 接下来就是拼接图片了。</h3><h4 id="这里的难点在于确定图片在哪个位置。"><a href="#这里的难点在于确定图片在哪个位置。" class="headerlink" title="这里的难点在于确定图片在哪个位置。"></a>这里的难点在于确定图片在哪个位置。</h4><p>a、图片数小于4时， 只有一行， 每张图片的 y 值都是0， x 值随图片数每次递增200px。<br>b、图片数大于3时， 循环复制图片到画布上， 当图片的序号等于列数的倍数时， 就要换行， 那么 x 值从0开始， y 值递增200px； 以此类推，直到所有图片复制到画布上。</p>
<p>代码如下：</p>
<figure class="highlight php"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 合并图片</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="keyword">public</span> <span class="function"><span class="keyword">function</span> <span class="title">combine</span><span class="params">()</span> </span>&#123;</span><br><span class="line">    <span class="keyword">if</span> (<span class="keyword">empty</span>(<span class="keyword">$this</span>-&gt;srcImages)  || <span class="keyword">$this</span>-&gt;width==<span class="number">0</span> || <span class="keyword">$this</span>-&gt;height==<span class="number">0</span>) &#123;</span><br><span class="line">        <span class="keyword">return</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    $imageCount = count(<span class="keyword">$this</span>-&gt;srcImages);</span><br><span class="line">    <span class="keyword">$this</span>-&gt;prepareForCanvas($imageCount);</span><br><span class="line">    <span class="keyword">for</span>($i=<span class="number">0</span>; $i&lt; $imageCount; $i++) &#123;</span><br><span class="line">        $srcImage = <span class="keyword">$this</span>-&gt;srcImages[$i];</span><br><span class="line">        $srcImageInfo = getimagesize($srcImage);</span><br><span class="line">        <span class="comment">// 如果能够正确的获取原图的基本信息</span></span><br><span class="line">        <span class="keyword">if</span> ($srcImageInfo) &#123;</span><br><span class="line">            $srcWidth = $srcImageInfo[<span class="number">0</span>];</span><br><span class="line">            $srcHeight = $srcImageInfo[<span class="number">1</span>];</span><br><span class="line">            $fileType = $srcImageInfo[<span class="number">2</span>];</span><br><span class="line">            <span class="keyword">if</span> ($fileType == <span class="number">2</span>) &#123;</span><br><span class="line">                <span class="comment">// 原图是 jpg 类型</span></span><br><span class="line">                $srcImage = imagecreatefromjpeg($srcImage);</span><br><span class="line">            &#125; <span class="keyword">else</span> <span class="keyword">if</span> ($fileType == <span class="number">3</span>) &#123;</span><br><span class="line">                <span class="comment">// 原图是 png 类型</span></span><br><span class="line">                $srcImage = imagecreatefrompng($srcImage);</span><br><span class="line">            &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">                <span class="comment">// 无法识别的类型</span></span><br><span class="line">                <span class="keyword">continue</span>;</span><br><span class="line">            &#125;</span><br><span class="line"></span><br><span class="line">            <span class="comment">//只支持横向</span></span><br><span class="line">            <span class="comment">// 计算当前原图片应该位于画布的哪个位置</span></span><br><span class="line">            <span class="keyword">if</span> ($i &lt; <span class="keyword">$this</span>-&gt;eachLineCount)&#123;</span><br><span class="line">                $destX = $i * <span class="keyword">$this</span>-&gt;width;</span><br><span class="line">                $desyY = <span class="number">0</span>;</span><br><span class="line">                $currentRowIndex = <span class="number">0</span>;</span><br><span class="line">            &#125;<span class="keyword">else</span>&#123;</span><br><span class="line">                <span class="comment">//计算该图片应该在第几行， 第几列</span></span><br><span class="line">                 $tmp = ($i+<span class="number">1</span>)/<span class="keyword">$this</span>-&gt;eachLineCount;</span><br><span class="line">                <span class="keyword">if</span> (($i+<span class="number">1</span>)%<span class="keyword">$this</span>-&gt;eachLineCount == <span class="number">0</span>)&#123;</span><br><span class="line">                    $currentRowIndex = $tmp <span class="number">-1</span>;</span><br><span class="line">                &#125;<span class="keyword">else</span>&#123;</span><br><span class="line">                    $currentRowIndex = floor($tmp);</span><br><span class="line">                &#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">                $destX = ($i - $currentRowIndex*<span class="keyword">$this</span>-&gt;eachLineCount)*<span class="keyword">$this</span>-&gt;width;</span><br><span class="line">                $desyY = $currentRowIndex*<span class="keyword">$this</span>-&gt;height;</span><br><span class="line">            &#125;</span><br><span class="line"></span><br><span class="line">            <span class="keyword">echo</span> <span class="string">'当前索引:'</span>.$i.<span class="string">',当前行的索引: '</span>.$currentRowIndex.<span class="string">',图片位置 X: '</span>.$destX.<span class="string">',图片位置 Y: '</span>.$desyY.PHP_EOL;</span><br><span class="line"></span><br><span class="line">            imagecopyresampled(<span class="keyword">$this</span>-&gt;canvas, $srcImage, $destX, $desyY,</span><br><span class="line">                <span class="number">0</span>, <span class="number">0</span>, <span class="keyword">$this</span>-&gt;width, <span class="keyword">$this</span>-&gt;height, $srcWidth, $srcHeight);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">// 如果有指定目标地址，则输出到文件</span></span><br><span class="line">    <span class="keyword">if</span> ( ! <span class="keyword">empty</span>(<span class="keyword">$this</span>-&gt;destImage)) &#123;</span><br><span class="line">        <span class="keyword">$this</span>-&gt;output();</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="5、效果预览"><a href="#5、效果预览" class="headerlink" title="5、效果预览"></a>5、效果预览</h3><p><img src="https://ws1.sinaimg.cn/large/006tKfTcgy1fgfalih389j30b40b40t8.jpg" alt=""></p>
<p><img src="https://ws1.sinaimg.cn/large/006tKfTcgy1fgfalhd9z8j30rs0m8acd.jpg" alt=""></p>
<h3 id="6、完整的代码"><a href="#6、完整的代码" class="headerlink" title="6、完整的代码"></a>6、完整的代码</h3><p><a href="https://github.com/moxun33/imageMergerUtil" target="_blank" rel="noopener">https://github.com/moxun33/imageMergerUtil</a></p>

      
    </div>

    

    
    
    

    

    
      
    
    

    

    <footer class="post-footer">
      
        
          
        
        <div class="post-tags">
          
            <a href="/tags/PHP/" rel="tag"># PHP</a>
          
            <a href="/tags/微信/" rel="tag"># 微信</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2017/05/27/闲谈-PHP7新特性/" rel="next" title="闲谈 PHP7新特性">
                <i class="fa fa-chevron-left"></i> 闲谈 PHP7新特性
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2017/07/08/聊聊-web-中的网络请求/" rel="prev" title="聊聊 web 中的网络请求">
                聊聊 web 中的网络请求 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>


  </div>


          </div>
          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope="" itemtype="http://schema.org/Person">
            
              <p class="site-author-name" itemprop="name">启码匠</p>
              <div class="site-description motion-element" itemprop="description">学习如磨刀， 需要不断温故。</div>
          </div>

          
            <nav class="site-state motion-element">
              
                <div class="site-state-item site-state-posts">
                
                  <a href="/archives/">
                
                    <span class="site-state-item-count">34</span>
                    <span class="site-state-item-name">日志</span>
                  </a>
                </div>
              

              

              
                
                
                <div class="site-state-item site-state-tags">
                  
                    
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                    <span class="site-state-item-count">47</span>
                    <span class="site-state-item-name">标签</span>
                  
                </div>
              
            </nav>
          

          

          

          

          

          
          

          
            
          
          

        </div>
      </div>

      
      <!--noindex-->
        <div class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
            
            
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-3"><a class="nav-link" href="#1、如何选一个微信爬虫。"><span class="nav-number">1.</span> <span class="nav-text">1、如何选一个微信爬虫。</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#所谓的微信爬虫就是利用微信的-web-api-做一些自动化的事情，这里强烈推荐由-PHP7实现的vbot-所有的东西都可以在-vbot-的文档里找到，-在微信-web-api-的范围内你都可以为所欲为了。注意：-本文所有的微信数据都基于-vbot-获取的。"><span class="nav-number">1.1.</span> <span class="nav-text">所谓的微信爬虫就是利用微信的 web api 做一些自动化的事情，这里强烈推荐由 PHP7实现的vbot, 所有的东西都可以在 vbot 的文档里找到， 在微信 web api 的范围内你都可以为所欲为了。注意： 本文所有的微信数据都基于 vbot 获取的。</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2、如何爬取微信好友的头像。"><span class="nav-number">2.</span> <span class="nav-text">2、如何爬取微信好友的头像。</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#首先要获取的是你的微信好友列表，-在-vbot-的基础上我们可以这样做："><span class="nav-number">2.1.</span> <span class="nav-text">首先要获取的是你的微信好友列表， 在 vbot 的基础上我们可以这样做：</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#把微信好友列表写入到一个文件中。"><span class="nav-number">2.2.</span> <span class="nav-text">把微信好友列表写入到一个文件中。</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#然后对这个文件进行处理，-提取微信好友的头像链接和下载。"><span class="nav-number">2.3.</span> <span class="nav-text">然后对这个文件进行处理， 提取微信好友的头像链接和下载。</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#就这样，-我们就已经能把所有的微信好友头像下载到指定的地方了。注意：建议图片的命名规则用数字递增的方式，-方便后面的图片拼接循环。"><span class="nav-number">2.4.</span> <span class="nav-text">就这样， 我们就已经能把所有的微信好友头像下载到指定的地方了。注意：建议图片的命名规则用数字递增的方式， 方便后面的图片拼接循环。</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3、图片拼接"><span class="nav-number">3.</span> <span class="nav-text">3、图片拼接</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#本文的重点来了，-现在网上有很多图片拼接小工具，-但-PHP-实现的寥寥无几，-找了一轮后，-决定还是自己写。"><span class="nav-number">3.1.</span> <span class="nav-text">本文的重点来了， 现在网上有很多图片拼接小工具， 但 PHP 实现的寥寥无几， 找了一轮后， 决定还是自己写。</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#4、画布建好了，-接下来就是拼接图片了。"><span class="nav-number">4.</span> <span class="nav-text">4、画布建好了， 接下来就是拼接图片了。</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#这里的难点在于确定图片在哪个位置。"><span class="nav-number">4.1.</span> <span class="nav-text">这里的难点在于确定图片在哪个位置。</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#5、效果预览"><span class="nav-number">5.</span> <span class="nav-text">5、效果预览</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#6、完整的代码"><span class="nav-number">6.</span> <span class="nav-text">6、完整的代码</span></a></li></ol></div>
            

          </div>
        </div>
      <!--/noindex-->
      

      

    </div>
  </aside>
  


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2019</span>
  <span class="with-love" id="animate">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">启码匠</span>

  

  
</div>


  <div class="powered-by">由 <a href="https://hexo.io" class="theme-link" rel="noopener" target="_blank">Hexo</a> 强力驱动 v3.9.0</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 – <a href="https://theme-next.org" class="theme-link" rel="noopener" target="_blank">NexT.Muse</a> v7.1.2</div>




        
<div class="busuanzi-count">
  <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>

  

  

  
</div>









        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

    

    
  </div>

  

<script>
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>


























  
  <script src="/lib/jquery/index.js?v=3.4.1"></script>

  
  <script src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>


  


  <script src="/js/utils.js?v=7.1.2"></script>

  <script src="/js/motion.js?v=7.1.2"></script>



  
  


  <script src="/js/schemes/muse.js?v=7.1.2"></script>



  
  <script src="/js/scrollspy.js?v=7.1.2"></script>
<script src="/js/post-details.js?v=7.1.2"></script>



  


  <script src="/js/next-boot.js?v=7.1.2"></script>


  

  

  

  


  


  
  <script>
    // Popup Window;
    var isfetched = false;
    var isXml = true;
    // Search DB path;
    var search_path = "search.xml";
    if (search_path.length === 0) {
      search_path = "search.xml";
    } else if (/json$/i.test(search_path)) {
      isXml = false;
    }
    var path = "/" + search_path;
    // monitor main search box;

    var onPopupClose = function (e) {
      $('.popup').hide();
      $('#local-search-input').val('');
      $('.search-result-list').remove();
      $('#no-result').remove();
      $(".local-search-pop-overlay").remove();
      $('body').css('overflow', '');
    }

    function proceedsearch() {
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay"></div>')
        .css('overflow', 'hidden');
      $('.search-popup-overlay').click(onPopupClose);
      $('.popup').toggle();
      var $localSearchInput = $('#local-search-input');
      $localSearchInput.attr("autocapitalize", "none");
      $localSearchInput.attr("autocorrect", "off");
      $localSearchInput.focus();
    }

    // search function;
    var searchFunc = function(path, search_id, content_id) {
      'use strict';

      // start loading animation
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay">' +
          '<div id="search-loading-icon">' +
          '<i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>' +
          '</div>' +
          '</div>')
        .css('overflow', 'hidden');
      $("#search-loading-icon").css('margin', '20% auto 0 auto').css('text-align', 'center');

      

      $.ajax({
        url: path,
        dataType: isXml ? "xml" : "json",
        async: true,
        success: function(res) {
          // get the contents from search data
          isfetched = true;
          $('.popup').detach().appendTo('.header-inner');
          var datas = isXml ? $("entry", res).map(function() {
            return {
              title: $("title", this).text(),
              content: $("content",this).text(),
              url: $("url" , this).text()
            };
          }).get() : res;
          var input = document.getElementById(search_id);
          var resultContent = document.getElementById(content_id);
          var inputEventFunction = function() {
            var searchText = input.value.trim().toLowerCase();
            var keywords = searchText.split(/[\s\-]+/);
            if (keywords.length > 1) {
              keywords.push(searchText);
            }
            var resultItems = [];
            if (searchText.length > 0) {
              // perform local searching
              datas.forEach(function(data) {
                var isMatch = false;
                var hitCount = 0;
                var searchTextCount = 0;
                var title = data.title.trim();
                var titleInLowerCase = title.toLowerCase();
                var content = data.content.trim().replace(/<[^>]+>/g,"");
                
                var contentInLowerCase = content.toLowerCase();
                var articleUrl = decodeURIComponent(data.url).replace(/\/{2,}/g, '/');
                var indexOfTitle = [];
                var indexOfContent = [];
                // only match articles with not empty titles
                if(title != '') {
                  keywords.forEach(function(keyword) {
                    function getIndexByWord(word, text, caseSensitive) {
                      var wordLen = word.length;
                      if (wordLen === 0) {
                        return [];
                      }
                      var startPosition = 0, position = [], index = [];
                      if (!caseSensitive) {
                        text = text.toLowerCase();
                        word = word.toLowerCase();
                      }
                      while ((position = text.indexOf(word, startPosition)) > -1) {
                        index.push({position: position, word: word});
                        startPosition = position + wordLen;
                      }
                      return index;
                    }

                    indexOfTitle = indexOfTitle.concat(getIndexByWord(keyword, titleInLowerCase, false));
                    indexOfContent = indexOfContent.concat(getIndexByWord(keyword, contentInLowerCase, false));
                  });
                  if (indexOfTitle.length > 0 || indexOfContent.length > 0) {
                    isMatch = true;
                    hitCount = indexOfTitle.length + indexOfContent.length;
                  }
                }

                // show search results

                if (isMatch) {
                  // sort index by position of keyword

                  [indexOfTitle, indexOfContent].forEach(function (index) {
                    index.sort(function (itemLeft, itemRight) {
                      if (itemRight.position !== itemLeft.position) {
                        return itemRight.position - itemLeft.position;
                      } else {
                        return itemLeft.word.length - itemRight.word.length;
                      }
                    });
                  });

                  // merge hits into slices

                  function mergeIntoSlice(text, start, end, index) {
                    var item = index[index.length - 1];
                    var position = item.position;
                    var word = item.word;
                    var hits = [];
                    var searchTextCountInSlice = 0;
                    while (position + word.length <= end && index.length != 0) {
                      if (word === searchText) {
                        searchTextCountInSlice++;
                      }
                      hits.push({position: position, length: word.length});
                      var wordEnd = position + word.length;

                      // move to next position of hit

                      index.pop();
                      while (index.length != 0) {
                        item = index[index.length - 1];
                        position = item.position;
                        word = item.word;
                        if (wordEnd > position) {
                          index.pop();
                        } else {
                          break;
                        }
                      }
                    }
                    searchTextCount += searchTextCountInSlice;
                    return {
                      hits: hits,
                      start: start,
                      end: end,
                      searchTextCount: searchTextCountInSlice
                    };
                  }

                  var slicesOfTitle = [];
                  if (indexOfTitle.length != 0) {
                    slicesOfTitle.push(mergeIntoSlice(title, 0, title.length, indexOfTitle));
                  }

                  var slicesOfContent = [];
                  while (indexOfContent.length != 0) {
                    var item = indexOfContent[indexOfContent.length - 1];
                    var position = item.position;
                    var word = item.word;
                    // cut out 100 characters
                    var start = position - 20;
                    var end = position + 80;
                    if(start < 0){
                      start = 0;
                    }
                    if (end < position + word.length) {
                      end = position + word.length;
                    }
                    if(end > content.length){
                      end = content.length;
                    }
                    slicesOfContent.push(mergeIntoSlice(content, start, end, indexOfContent));
                  }

                  // sort slices in content by search text's count and hits' count

                  slicesOfContent.sort(function (sliceLeft, sliceRight) {
                    if (sliceLeft.searchTextCount !== sliceRight.searchTextCount) {
                      return sliceRight.searchTextCount - sliceLeft.searchTextCount;
                    } else if (sliceLeft.hits.length !== sliceRight.hits.length) {
                      return sliceRight.hits.length - sliceLeft.hits.length;
                    } else {
                      return sliceLeft.start - sliceRight.start;
                    }
                  });

                  // select top N slices in content

                  var upperBound = parseInt('1');
                  if (upperBound >= 0) {
                    slicesOfContent = slicesOfContent.slice(0, upperBound);
                  }

                  // highlight title and content

                  function highlightKeyword(text, slice) {
                    var result = '';
                    var prevEnd = slice.start;
                    slice.hits.forEach(function (hit) {
                      result += text.substring(prevEnd, hit.position);
                      var end = hit.position + hit.length;
                      result += '<b class="search-keyword">' + text.substring(hit.position, end) + '</b>';
                      prevEnd = end;
                    });
                    result += text.substring(prevEnd, slice.end);
                    return result;
                  }

                  var resultItem = '';

                  if (slicesOfTitle.length != 0) {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + highlightKeyword(title, slicesOfTitle[0]) + "</a>";
                  } else {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + title + "</a>";
                  }

                  slicesOfContent.forEach(function (slice) {
                    resultItem += "<a href='" + articleUrl + "'>" +
                      "<p class=\"search-result\">" + highlightKeyword(content, slice) +
                      "...</p>" + "</a>";
                  });

                  resultItem += "</li>";
                  resultItems.push({
                    item: resultItem,
                    searchTextCount: searchTextCount,
                    hitCount: hitCount,
                    id: resultItems.length
                  });
                }
              })
            };
            if (keywords.length === 1 && keywords[0] === "") {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-search fa-5x"></i></div>'
            } else if (resultItems.length === 0) {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-frown-o fa-5x"></i></div>'
            } else {
              resultItems.sort(function (resultLeft, resultRight) {
                if (resultLeft.searchTextCount !== resultRight.searchTextCount) {
                  return resultRight.searchTextCount - resultLeft.searchTextCount;
                } else if (resultLeft.hitCount !== resultRight.hitCount) {
                  return resultRight.hitCount - resultLeft.hitCount;
                } else {
                  return resultRight.id - resultLeft.id;
                }
              });
              var searchResultList = '<ul class=\"search-result-list\">';
              resultItems.forEach(function (result) {
                searchResultList += result.item;
              })
              searchResultList += "</ul>";
              resultContent.innerHTML = searchResultList;
            }
          }

          if ('auto' === 'auto') {
            input.addEventListener('input', inputEventFunction);
          } else {
            $('.search-icon').click(inputEventFunction);
            input.addEventListener('keypress', function (event) {
              if (event.keyCode === 13) {
                inputEventFunction();
              }
            });
          }

          // remove loading animation
          $(".local-search-pop-overlay").remove();
          $('body').css('overflow', '');

          proceedsearch();
        }
      });
    }

    // handle and trigger popup window;
    $('.popup-trigger').click(function(e) {
      e.stopPropagation();
      if (isfetched === false) {
        searchFunc(path, 'local-search-input', 'local-search-result');
      } else {
        proceedsearch();
      };
    });

    $('.popup-btn-close').click(onPopupClose);
    $('.popup').click(function(e){
      e.stopPropagation();
    });
    $(document).on('keyup', function (event) {
      var shouldDismissSearchPopup = event.which === 27 &&
        $('.search-popup').is(':visible');
      if (shouldDismissSearchPopup) {
        onPopupClose();
      }
    });
  </script>





  

  

  

  

  

  

  

  

  

  

  

  

  

  

<script src="/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"pluginRootPath":"live2dw/","pluginJsPath":"lib/","pluginModelPath":"assets/","tagMode":false,"log":false,"model":{"jsonPath":"/live2dw/assets/shizuku.model.json"},"display":{"position":"left","width":150,"height":300},"mobile":{"show":true}});</script></body>
</html>
